-- NewPlayerPanel
-- NewPlayerPanel

local NewEquipRender = require("app.newBag.views.renders.NewEquipRender")
local NewPlayerClothesRender = require("app.newBag.views.renders.NewPlayerClothesRender")
local AvatarFactory = app:getClass("AvatarFactory")
local CorePropUIHelp = require("app.coreProp.CorePropUIHelp")
local ClassRef = app.mvc.createPanelClass(...)

local Strengthen_NUM = 2 -- 强化信息节点

local strengthenPanelBaseWidth = 227 -- 从UI中拿的值
local strengthenPanelBaseHeight = 53
local eachAttrPanelHeight = 25

function ClassRef.create(node)
	local publisher = app:getInnerPublisher()
	local res
	if publisher == Enums.Publisher.tencent then
		res = Res.NewPlayerPanelNode_tencent
	else
		res = Res.NewPlayerPanelNode
	end

	local sprite = ClassRef.extend(node or cc.CSLoader:createNode(res, true, true))
	if node == nil then
		ccui.Helper:doLayout(sprite)
	end
	sprite:init()
	return sprite
end

-- draw call 优化
function ClassRef:drawCallFix()
	local RootPanel = self._ui["Panel"]
	local panelChildren = RootPanel:getChildren()
	for i, panelChild in ipairs(panelChildren) do
		panelChild:setLocalZOrder(i)
		if panelChild:getName() == "Panel_equip"  then
			local equipChildren = panelChild:getChildren()
		
			local multipleLayersParentNode = custom.MultipleLayersParentNode:create(9)
			multipleLayersParentNode:copyProp(panelChild)
			for _,equipChild in ipairs(equipChildren) do
				local name = equipChild:getName()
				local zorder = equipChild:getLocalZOrder()
				local action = equipChild:getTimeline()

				local panel = equipChild:getChildByName('Panel')
				panel:setScaleX(equipChild:getScaleX())
				panel:setScaleY(equipChild:getScaleY())

				local multipleLayersNode = display.replaceNodeToMultipleLayerNode(panel)
				local newAction

				if action then
					local newAction = action:clone()
					multipleLayersNode:runAction(newAction)
					newAction:gotoFrameAndPlay(0, true)
				end
				equipChild:removeFromParent()
				multipleLayersNode:setPosition(equipChild:getPosition())
				multipleLayersNode:setLocalZOrder(zorder)
				multipleLayersNode:setName(name)
				multipleLayersParentNode:addChild(multipleLayersNode)
			end
			panelChild:removeFromParent(true)
			RootPanel:addChild(multipleLayersParentNode)
		end
	end
end

function ClassRef:init(data)
	self.super.init(self, data)
	self:getTimeline():gotoFrameAndPause(0)

	self._isBtmAniShown = false
	self._isTopAniShown = false
	self._curRender = nil -- 当前选中的人物身上的装备
	self._curClothesRender = nil -- 当前选中的人物身上的时装
	self._equipGridStrengthPanelShown = false -- 装备强化panel是否显示
	self._clickHandler = nil
	self:drawCallFix()
	--hero touch check
	local touchLayer = display.newLayer()
    touchLayer:setContentSize(display.width,display.height)
    touchLayer:setTouchEnabled(true)
    self:addChild(touchLayer)
	local touchListener = cc.EventListenerTouchOneByOne:create()
    touchListener:registerScriptHandler(function(touch, event)
    	local locationX,locationY = touch:getLocation2()
    	local playArmature = self._ui.Node_position:getChildByTag(0)
    	if playArmature and playArmature:containWorldPoint(locationX,locationY) then
    		self:playNextAnimation()
    	end
    	return false
    end,cc.Handler.EVENT_TOUCH_BEGAN)
    self:getEventDispatcher():addEventListenerWithSceneGraphPriority(touchListener, touchLayer)
	self:setCorePropBtnVisible(true)

	-- init equip
	self._equips = {}
	local children = self._ui["Panel/Panel_equip"]:getChildren()


	for _,equipTemp in ipairs(children) do
		local name = equipTemp:getName()
		local idx = tonumber(string.split(name,"_")[2])
		local render = NewEquipRender.create(equipTemp)
		render:setDefPos(idx)
		render:setData()
		render:setClickHandler(function(render)
				local isSelect = render:isSelected()
				if self._curRender ~= render then
					self:unselectedCurRender()
				end
				self._curRender = isSelect and render or nil
				if self._curRender and not self._curRender:getData() then
					self._curRender:setSelected(false)
					self._curRender = nil
				end
				if self._equipGridStrengthPanelShown then -- 在装备强化UI显示时选中其他装备
					if string.find( GD:getSystemStrPar("recastlocation", "nil"), tostring( idx ) ) then
						executeFunc(self._clickHandler, "PlayerPanel_selectedOtherEquipWhenStrengthShown", render)
					else
						display.pushToast(L("tips_3000332"))
					end
				else
					executeFunc(self._clickHandler, "PlayerPanel_showEquipTip", render)
				end
			end)
		display.setCascadeColorEnabled(render,true)
		self._equips[idx] = render
	end

	-- msdk
	self._wxIcon = self._ui["Panel/Panel_top/icon_wx"]
	if self._wxIcon  then
		self._wxIcon:setVisible(UD.msdkData:isMyWakeUpFromWXGame())
	end
	-- init top
	self._class_icon = self._ui["Panel/Panel_top/class_icon"]
	self._name_player = self._ui["Panel/Panel_top/name_player"]
	self._lv_num = self._ui["Panel/Panel_top/lv_num"]
	self._job_name = self._ui["Panel/Panel_top/job_name"]
	self._combat_num = self._ui["Panel/Panel_top/combat_num"]
	self._ui["Panel/Panel_top/Button_date"]:addClickEventListener(function()
			if not self._isTopAniShown then
				self._isTopAniShown = true
				self:setTopPopUpPanelVisble(1)
				self:getTimeline():play( "top_in", false )
				self._ui["Panel/Panel_animation/top"]:setVisible( true )
				self._ui["Panel/Panel_animation/bom"]:setVisible( false )
				self._ui["Panel/Panel_top/Button_date"]:setVisible( false )
				self:setRecastMasterBtnVisible(false)
				self:setCorePropBtnVisible(false)
				executeFunc(self._onPanelHandler, "PlayerPanel_ReqAttrList", "attr")
			end
	end)
	self._ui["Panel/Panel_top/Button_qh"]:addClickEventListener(function()
		if not self._isTopAniShown then
			self._isTopAniShown = true
			self:setTopPopUpPanelVisble(3)
			self:getTimeline():play( "top_in", false )
			self._ui["Panel/Panel_animation/top"]:setVisible( true )
			self._ui["Panel/Panel_animation/bom"]:setVisible( false )
			self._ui["Panel/Panel_top/Button_date"]:setVisible( false )
			self:setRecastMasterBtnVisible(false)
			self:setCorePropBtnVisible(false)
			executeFunc(self._onPanelHandler, "PlayerPanel_ReqAttrList", "recastMaster")
		end
	end)
	self._ui["Panel/Panel_top/Button_CoreProp"]:addClickEventListener(function()
			executeFunc(self._onPanelHandler, "PlayerPanel_OpenCorePropView")
	end)

	display.nodeRemoveForNotHit(self._ui["Panel/Panel_animation/top"]:getChildByName( "Panel" ), function()
			if self._isTopAniShown then
				self._isTopAniShown = false
				self:getTimeline():play( "top_out",false )
				self._ui["Panel/Panel_animation/top"]:setVisible( false )
				self._ui["Panel/Panel_top/Button_date"]:setVisible( true )
				self:setRecastMasterBtnVisible(true)
				self:setCorePropBtnVisible(true)
			end
		end)

	self._ui["Panel/Panel_animation/top"]:findChild("Panel/Panel_qh/Button_quxiao"):addClickEventListener(function()
		executeFunc(self._onPanelHandler, "quickStrength")
	end)


    self._ui["Panel/btn_show"]:setVisible(self._isOtherPlayer ~= true)
    self:refreshHiddenBtnState()
    self._ui["Panel/btn_show"]:addClickEventListener(function()     
            executeFunc(self._onPanelHandler, "PlayerPanel_ShowHeadFashion") 
        end)

	-- init bom
	self._icon_1_gold = self._ui["Panel/Panel_bom/icon_1_gold"]
	self._icon_2 = self._ui["Panel/Panel_bom/icon_2"]
	self._icon_3 = self._ui["Panel/Panel_bom/icon_3"]

	local coinConfig = GD:getCoinConfig( Enums.PropType.gold )
	local iconPath = GD:getImagePath(Res.coinIconPath,coinConfig.bigicon)
	self._icon_1_gold:loadTexture( iconPath )

	coinConfig = GD:getCoinConfig( Enums.PropType.coinRes92 )
	iconPath = GD:getImagePath(Res.coinIconPath,coinConfig.bigicon)
	self._icon_2:loadTexture( iconPath )


	local publisher = app:getInnerPublisher()

	if self._icon_3 and publisher ~= Enums.Publisher.tencent then
		coinConfig = GD:getCoinConfig( Enums.PropType.magicCrystal )
		iconPath = GD:getImagePath(Res.coinIconPath,coinConfig.bigicon)
		self._icon_3:loadTexture( iconPath )
	end

	self._num_1_gold = self._ui["Panel/Panel_bom/num_1_gold"]
	self._num_2 = self._ui["Panel/Panel_bom/num_2"]
	self._num_3 = self._ui["Panel/Panel_bom/num_3"]
	self._ui["Panel/Panel_bom/Button_bg"]:setTouchEnabled( false )
	self._ui["Panel/Panel_bom"]:addClickEventListener(function()
			if not self._isBtmAniShown then -- 之前不可见？
				self._isBtmAniShown = true

				self._ui["Panel/Panel_animation/bom"]:setVisible( true )
				self:getTimeline():play( "bom_in", false )
			else
				self._isBtmAniShown = false
				self._ui["Panel/Panel_animation/bom"]:setVisible( false )
				self:getTimeline():play( "bom_out",false )
			end

			if self._isTopAniShown then
				self._isTopAniShown = false
				self._ui["Panel/Panel_animation/top"]:setVisible( false )
				self._ui["Panel/Panel_top/Button_date"]:setVisible( true )
				self:setRecastMasterBtnVisible(true)
				self:setCorePropBtnVisible(true)
				
			end
		end)
	display.nodeRemoveForNotHit(self._ui["Panel/Panel_bom"], function()
			if self._isBtmAniShown then
				self._isBtmAniShown = false

				self._ui["Panel/Panel_animation/bom"]:setVisible( false )
				self:getTimeline():play( "bom_out",false )
			end
		end)

	self:performWithDelay( handler(self, self.delayInit), 0 ) -- 后显示UI丢到后面处理，不阻塞在这里
end



-- 延迟初始化的部分
function ClassRef:delayInit()
	-- init clothes
	self._clothes = {}
	local children = self._ui["Panel/Panel_clothes"]:getChildren()
	for _,clothesTemp in ipairs(children) do
		local name = clothesTemp:getName()
		local idx = tonumber(string.split(name,"_")[2])
		local render = NewPlayerClothesRender.create(clothesTemp)
		render:setClothesDefPos(idx)
		render:setClickHandler(function(render)
				self._curClothesRender = render or nil
				if self._curClothesRender and not self._curClothesRender:getData() then
					self._curClothesRender = nil
				end
				executeFunc(self._clickHandler, "PlayerPanel_selectedClothes", render)
			end)
		self._clothes[idx] = render
	end

	-- init bom popup UI

	local publisher = app:getInnerPublisher()
	local maxI = 3
	if publisher ~= Enums.Publisher.tencent then
		maxI = 3
	else
		maxI = 2
	end

	for i = 1, maxI do
		local moneyDescPanel = self._ui["Panel/Panel_animation/bom/Panel"]:getChildByName( "gold_"..i )
		if moneyDescPanel then
			local moneyDescNode = moneyDescPanel:getChildByName( "Panel" )
			local coinConf =  nil
			if 1 == i then
				coinConf = GD:getCoinConfig( Enums.PropType.gold )
			elseif 2 == i then
				coinConf = GD:getCoinConfig( Enums.PropType.coinRes92 )
			elseif 3 == i then
				coinConf = GD:getCoinConfig( Enums.PropType.magicCrystal )
			end

			local iconPath = GD:getImagePath(Res.coinIconPath,coinConf.bigicon)
			moneyDescNode:getChildByName( "icon" ):loadTexture( iconPath )

			local descStr =  L(coinConf.name) .. ":" .. L(coinConf.des)
			moneyDescNode:getChildByName( "Text" ):setString( descStr )
		end

	end
end

function ClassRef:refresh()
	if self._data then
		-- others
		self:setClothesVisible(false)
		self:refreshEquips(self._data.equips)
		self:refreshPlayer(self._data.baseInfo)

		-- 更新所有格子的强化等级 & 不显示可强化提示
		for _, grid in ipairs(self._equips) do
			local lv = self._data.equipGridStrengths[ grid:getDefPos() ]
			if not lv then lv = 0 end
			grid:setStrengthenedLv(lv)

			grid:setContinueStrengthen(false)
		end
	else
		local heroParams = UD:getAvatarParams()
		self:refreshEquips(UD.equips)
		self:refreshPlayer(heroParams)
	end

	self:refreshTopInfo()
	self:refreshBomInfo()
	self:refreshRedPonit()
end

-- 回调处理
function ClassRef:setClickHandler(cb)
	self._clickHandler = cb
end

-- 装备信息弹出？
function ClassRef:setEquipTipEnable(b)
	for i,equip in ipairs(self._equips) do
		equip:setTipEnable(b)
	end
end
-- 返回当前选中的装备
function ClassRef:getCurSelectedEquip()
	return self._curRender
end
-- 取消选中当前Render（装备）
function ClassRef:unselectedCurRender()
	if self._curRender then
		self._curRender:setSelected(false)
		self._curRender = nil
	end
end

-- 刷新对应位置的装备
function ClassRef:refreshEquipByPos(pos, equip, op)
	if op ~= "delete" then
		self._equips[pos]:setData(equip)
		self:refreshClothesByPos( pos )
	else
		self._equips[pos]:setData(nil)
		self:refreshClothesByPos( pos )
	end

	-- 统一走EquipGrid变化，所有Equip变化都会引起EquipGrid变化
	-- if op ~= "update" and equip:hasAvatar() then
	-- 	-- 1.穿／卸装备 2.该装备有avatar 更新形象
	-- 	local equipGrid = UD:getEquipGridByPos(pos)
	-- 	if equipGrid:getFashionId() > 0 then
	-- 		self:refreshPlayer( UD:getAvatarParams(), equipGrid:getFashionId(), op == "delete")
	-- 	else
	-- 		self:refreshPlayer( UD:getAvatarParams(), equip:getId(), op == "delete")
	-- 	end
	-- end
end

--从快捷按钮点击进来的时候选中一个可以强化的装备按钮 若没有 则不做什么
function ClassRef:setDefaultSelectEquipGrid()
	for k,v in ipairs(self._equips) do
		if v then
			local equip = UD:getEquipByPos(v:getDefPos())
			if equip then
				return v:getData()
			end
		end
	end
end

--幻化成功或者取消后都要更新
function ClassRef:updateFashionByPos(equipGrid, preFashionId, hasAvatarChange, hasHiddenChange)
	self:refreshClothesByPos( equipGrid:getLocation() )
    if hasHiddenChange then
        self:refreshHiddenBtnState()
    end
	if hasAvatarChange or hasHiddenChange then
		local params = UD:getAvatarParams()
        local hiddenFlag = equipGrid:getHidden()
		if preFashionId > 0 then
            local isOff = true
            if hasHiddenChange then
                isOff = hiddenFlag
            end
			self:refreshPlayer( params, preFashionId, isOff)
		end
		local fashionId = equipGrid:getAvatarFashionId()
		if fashionId > 0 then
			self:refreshPlayer( params, fashionId, hiddenFlag)
		end
	end
end

-- 获取对应位置的装备
function ClassRef:getEquipRender(pos)
	return self._equips[pos]
end
-- 刷新所有装备
function ClassRef:refreshEquips(equips)
	for _,equip in pairs(equips) do
		local pos = equip:getPos()
		local render = self._equips[pos]
		render:setData(equip)
	end

	self:refreshClothes()
end

--参数为升级的格子id
function ClassRef:refreshEquipGrids(lvGrids)
	for _,render in pairs(self._equips) do
		render:refresh()
	end

	for k,v in ipairs(lvGrids) do
		local render = self:getEquipRender(v)
		if render then
			render:playStrengthSuccessAmi()
		end
	end

	--playStrengthSuccessAmi
	self:refreshClothes()
	self._ui["Panel/Panel_top/Button_date"]:setVisible( false )
	self._ui["Panel/Panel_top/Button_CoreProp"]:setVisible( false )
	self._ui["Panel/Panel_top/Button_qh"]:setVisible( false )
end


-- 清空所有装备信息
function ClassRef:clearEquips()
	for i,equip in ipairs(self._equips) do
		equip:setData(nil)
	end
	self:clearClothes()
end

-- 时装panel是否显示
function ClassRef:setClothesVisible( clothesVisible )
	self._ui["Panel/Panel_clothes"]:setVisible( clothesVisible )
end

-- 收起上方属性弹窗
function ClassRef:packupStrengthPanel()
	if self._isTopAniShown then
		self._isTopAniShown = false
		self:getTimeline():play( "top_out",false )
		self._ui["Panel/Panel_animation/top"]:setVisible( false )
		self._ui["Panel/Panel_top/Button_date"]:setVisible( true )
		self:setRecastMasterBtnVisible(true)
		self:setCorePropBtnVisible(true)
	end
end

function ClassRef:setAttrAndStrengthShown( shown )
	self._ui["Panel/Panel_top/Button_date"]:setVisible( shown )
	self:setRecastMasterBtnVisible(shown)
	self:setCorePropBtnVisible(shown)

end

-- 选中某件时装
function ClassRef:selectedClothesRenderByPos( pos )
	self._curClothesRender = self._clothes[pos]
end
-- 取消选中当前Render（时装）
function ClassRef:unselectedCurClothesRender()
	if self._curClothesRender then
		--self._curClothesRender:setSelected(false)
		self._curClothesRender = nil
	end
end
-- 刷新对应位置的时装
function ClassRef:refreshClothesByPos( pos )
	if not self._clothes then return end

	local clothesRender = self._clothes[pos]
	local equipGrid = UD:getEquipGridByPos(pos)
	if clothesRender and equipGrid then
		if equipGrid:getFashionId() > 0 then
			clothesRender:setColor( display.COLOR_WHITE )
			clothesRender:setData( equipGrid:getFashionId() )
			clothesRender:addStartEffect()
		else
			clothesRender:setData( nil )
			clothesRender:setColor( display.COLOR_GRAY )
		end
	 end
end

-- 刷新所有时装
function ClassRef:refreshClothes()
	if not self._clothes then return end

	for k,v in pairs(self._clothes) do
		v:setColor( display.COLOR_GRAY )
		local defPos = v:getClothesDefPos()
		local equipGrid = UD:getEquipGridByPos(defPos)
		if equipGrid then
			v:setColor( display.COLOR_WHITE )
			if equipGrid:getFashionId() > 0 then
				v:setData( equipGrid:getFashionId() )
			end
		end
	end
end

-- 清空所有时装信息
function ClassRef:clearClothes()
	if not self._clothes then return end

	for _,clothes in ipairs(self._clothes) do
		clothes:setData(nil)
	end
end

-- 刷新上方人物信息
function ClassRef:refreshTopInfo()
	if self._data then -- 传进来的数据
		local baseInfo = self._data.baseInfo

		self._class_icon:loadTexture( baseInfo:getClassIcon() )
		self._job_name:setString( baseInfo:getDuty() )

		self._name_player:setString( baseInfo.name )
		self._lv_num:setString( baseInfo.level )

		self._combat_num:setString( string.format( L("lua_code_text_274"), baseInfo.combatPower ) )
	else
		local classIconPath = GD:getClassIcon( UD.player.classID, 2 )
		self._class_icon:loadTexture( classIconPath )

		self._name_player:setString( UD:getNickName() )
		self._lv_num:setString( UD:getLevel() )

		local skillChooseIdList = string.split( UD:getCurSpecTypeId(), "0" ) -- { 1, 1 }
		self._job_name:setString( L("class_" .. skillChooseIdList[1] .. "_" .. skillChooseIdList[2] ) .. L("class_"..UD.player.classID) )

		self._combat_num:setString( string.format( L("lua_code_text_274"), UD:getCombatPower() ) )
	end
end
-- 刷新下方货币信息
function ClassRef:refreshBomInfo()
	if self._data then
		self._ui["Panel/Panel_bom"]:setVisible( false )
		self._ui["Panel/Panel_animation/bom"]:setVisible( false )
		-- self._ui["Panel/Panel_top/Button_date"]:setVisible( false )
		-- self._ui["Panel/Panel_top/Button_Streng"]:setVisible( false )
	else
		self._ui["Panel/Panel_bom"]:setVisible( true )
		self._ui["Panel/Panel_animation/bom"]:setVisible( true )
		self._ui["Panel/Panel_top/Button_date"]:setVisible( true )
		self:setRecastMasterBtnVisible(true)
		self:setCorePropBtnVisible(true)

		self._num_1_gold:setString( UD:getGold() )
		self._num_2:setString( UD:getMagicDust() )

		local publisher = app:getInnerPublisher()

		if self._num_3 and publisher ~= Enums.Publisher.tencent then
			self._num_3:setString( UD:getMagicCrystal() )
		end
	end
end

-- 刷新属性
function ClassRef:refreshProp( proBaseAttrConf )
	proBaseAttrConf = proBaseAttrConf --or UD:getShownProp()
	-- dump( proBaseAttrConf, ' ---------------->>>>> test prop ' )

	if not self._attributeList then
		-- init top/attr -- 初始化属性列表
		local eachAttrNode = cc.CSLoader:createNode(Res.NewBagAttrNode) --每一条属性的节点
		local panelTemplate = eachAttrNode:getChildByName( "Panel" )
		panelTemplate:getChildByName( "num" ):setString( "" )

		self._attributeList = {}
		local ListView_data = self._ui["Panel/Panel_animation/top"]:getChildByName( "Panel" ):getChildByName( "ListView_data" )

		for i,v in ipairs( proBaseAttrConf ) do
			local CustomItemTemp = panelTemplate:clone()
			CustomItemTemp:setName( v[1] )
			table.insert( self._attributeList, CustomItemTemp )
			ListView_data:pushBackCustomItem( CustomItemTemp )
		end
	end
	
	for i,v in ipairs( self._attributeList ) do
		local name = string.gsub(L(v:getName()), "：+","") or ""
		name = string.gsub(name, ":+","") or ""
		v:getChildByName( "tlt" ):setString(name)
		local num = tonumber(proBaseAttrConf[i][2])
		if num == nil then
			num = 0
		end
		if proBaseAttrConf[i][3] == 2 and num ~= 0 then
			v:getChildByName( "num" ):setString( num / 100 .. "%")
		elseif proBaseAttrConf[i][3] == 3 and num ~= 0 then
			local strTemp = ""
			if (num / 1000) % 1 == 0 then
				strTemp = string.format("%.1f", num / 1000)
			else
				strTemp = string.format("%.2f", num / 1000)
			end
			v:getChildByName( "num" ):setString(strTemp)
		else
			v:getChildByName( "num" ):setString( num )
		end
		
	end
end
-- 刷新强化信息
function ClassRef:refreshStrengthenInfo( classID, minEquipStrengthLv )
-- 	classID = classID or UD.player.classID
-- 	minEquipStrengthLv = minEquipStrengthLv or UD.minEquipStrengthLv

-- 	if not self._strengthenList then
-- 		-- init top/strengthen -- 初始化强化列表
-- 		local eachStrengthenNode = cc.CSLoader:createNode(Res.NewBagStrengthenNode) --强化的节点
-- 		panelTemplate = eachStrengthenNode:getChildByName( "Panel" )
-- 		self._strengthenList = self._ui["Panel/Panel_animation/top"]:getChildByName( "Panel" ):getChildByName( "ListView_strengthen" )
-- 		for i = 1, Strengthen_NUM do
-- 			local CustomItemTemp = panelTemplate:clone()
-- 			CustomItemTemp:setName( 1 == i and "curStrengthenPanel" or "nextStrengthenPanel" )
-- 			self._strengthenList:pushBackCustomItem( CustomItemTemp )
-- 		end
-- 	end

-- 	local _curStrengthenPanel = self._strengthenList:getChildByName( "curStrengthenPanel" )
-- 	local _nextStrengthenPanel = self._strengthenList:getChildByName( "nextStrengthenPanel" )

-- 	local function fillStrengthenUIData( panelTemp, equipRecastBounesConf ) -- isCurLvNode-是否是当前等级属性节点
-- 		for i = 1, 5 do
-- 			panelTemp:getChildByName( "data_"..i ):getChildByName( "Panel" ):setVisible( false )
-- 		end

-- 		if equipRecastBounesConf then
-- 			panelTemp:setVisible( true )
-- 			panelTemp:getChildByName( "tlt" ):setString( string.format( L("全身强化到%d级"), tonumber( equipRecastBounesConf.bounesLevel ) ) )

-- 			local talentAffixList = GD:getTalentAffixConfig( equipRecastBounesConf.affix )
-- 			local count = 1
-- 			for k,v in pairs( talentAffixList ) do
-- 				if "ID" ~= k and tonumber( v ) > 0 then
-- 					panelTemp:getChildByName( "data_"..count ):getChildByName( "Panel" ):setVisible( true )

-- 					---------------->>>>>>>>>> 以下是从util中拷出来的解析属性格式的方法
-- 					local talentStateConf = GD:getTalentStateConfByName( k )
-- 					local Txt = 0
-- 					local Num = 0
--                     if talentStateConf.processing and talentStateConf.processing=="1" then
--                         Txt=-1*v
--                         Num=-1*v
--                     else
--                         Txt=v
--                         Num=v
--                     end
--                     if talentStateConf.format and talentStateConf.format=="2" then
--                         --2万分之一 显示%
--                         Txt=tostring(Num/100).."%"
--                     elseif talentStateConf.format and talentStateConf.format=="3" then
--                         --3千分之一 显示小数
--                         Txt=Num/1000
--                     elseif talentStateConf.format and talentStateConf.format=="4" then
--                         --4十分之一 显示小数一位
--                         Txt=Num/10
--                     else
--                         --整数
--                         Txt=math.ceil(tonumber(Num))
--                     end
--                     if talentStateConf.sign and talentStateConf.sign=="1" then
--                         Txt="+"..Txt
--                     elseif talentStateConf.sign and talentStateConf.sign=="2" then
--                         Txt="-"..Txt
--                     else
--                     end

--                     local nameTemp = talentStateConf.des and L(talentStateConf.des) or talentStateConf.name

-- 					panelTemp:getChildByName( "data_"..count ):getChildByName( "Panel" ):getChildByName( "tlt" ):setString( nameTemp )
-- 					panelTemp:getChildByName( "data_"..count ):getChildByName( "Panel" ):getChildByName( "num" ):setString( Txt )

-- 					count =  count + 1
-- 				end
-- 				assert( count <= 5 , " ------------------------->>>>>> 全身强化等级奖励属性条目数 > 5？？" )
-- 			end
-- 			panelTemp:setContentSize( cc.size( strengthenPanelBaseWidth, strengthenPanelBaseHeight + count * eachAttrPanelHeight ) )
-- 		else -- 无强化信息
-- 			panelTemp:setVisible( false )
-- 			panelTemp:setContentSize( cc.size( strengthenPanelBaseWidth, 0 ) )
-- 		end
-- 	end

-- 	local curBouncesConf = GD:getEquipRecastBounesByRecastLv( classID, minEquipStrengthLv )

-- 	local nextBouncesConf = nil
-- 	if curBouncesConf then
-- 		fillStrengthenUIData( _curStrengthenPanel, curBouncesConf )

-- 		nextBouncesConf = GD:getEquipRecastBounesByBouncesLv( classID, tonumber( curBouncesConf.bounesLevel ) + 1 )
-- 		fillStrengthenUIData( _nextStrengthenPanel, nextBouncesConf )
-- 	else -- 没强化过
-- 		fillStrengthenUIData( _curStrengthenPanel, nil )

-- 		nextBouncesConf = GD:getEquipRecastBounesByBouncesLv( classID, 1 )
-- 		fillStrengthenUIData( _nextStrengthenPanel, nextBouncesConf )
-- 	end

-- 	_nextStrengthenPanel:getChildByName( "tlt" ):setOpacity(255*0.5)
-- 	_nextStrengthenPanel:getChildByName( "line" ):setOpacity(255*0.5)
-- 	for i = 1, 5 do
-- 		local panelTemp = _nextStrengthenPanel:getChildByName( "data_"..i ):getChildByName( "Panel" )
-- 		panelTemp:getChildByName( "tlt" ):setOpacity(255*0.5)
-- 		panelTemp:getChildByName( "num" ):setOpacity(255*0.5)
-- 	end
end
-- 刷新战斗力
function ClassRef:refreshCombatPower( data )
	local combatPower = 0
	if data then
		combatPower = data[2]
	else
		combatPower = UD.player.combatPower
	end

	self._combat_num:setString( string.format( L("lua_code_text_274"), combatPower ) )
end
-- 刷新名字
function ClassRef:refreshPlayerName( newName )
	self._name_player:setString( newName )
end
-- 刷新货币1
function ClassRef:refreshGold(num)
	self._num_1_gold:setString( num )
end
-- 刷新货币2
function ClassRef:refreshMagicDust(num)
	self._num_2:setString( num )
end
-- 刷新货币3
function ClassRef:refreshMagicCrystal(num)
	local publisher = app:getInnerPublisher()
	if self._num_3 and publisher ~= Enums.Publisher.tencent then
		self._num_3:setString( num )
	end
end

-- 选择显示 属性/强化？
function ClassRef:setTopPopUpPanelVisble( tag ) -- 1-属性信息 2-强化信息
	if 1 == tag then
		self._ui["Panel/Panel_animation/top"]:getChildByName( "Panel" ):getChildByName( "ListView_data" ):setVisible( true )
		self._ui["Panel/Panel_animation/top"]:getChildByName( "Panel" ):getChildByName( "ListView_strengthen" ):setVisible( false )
		self._ui["Panel/Panel_animation/top"]:getChildByName( "Panel" ):getChildByName( "Panel_qh" ):setVisible( false )
	elseif 2 == tag then
		self._ui["Panel/Panel_animation/top"]:getChildByName( "Panel" ):getChildByName( "ListView_data" ):setVisible( false )
		self._ui["Panel/Panel_animation/top"]:getChildByName( "Panel" ):getChildByName( "ListView_strengthen" ):setVisible( false )
		self._ui["Panel/Panel_animation/top"]:getChildByName( "Panel" ):getChildByName( "Panel_qh" ):setVisible( false )
	elseif 3 == tag then
		self._ui["Panel/Panel_animation/top"]:getChildByName( "Panel" ):getChildByName( "ListView_data" ):setVisible( false )
		self._ui["Panel/Panel_animation/top"]:getChildByName( "Panel" ):getChildByName( "ListView_strengthen" ):setVisible( false )
		self._ui["Panel/Panel_animation/top"]:getChildByName( "Panel" ):getChildByName( "Panel_qh" ):setVisible( true )
	else
		-- print( " --------->>>>>>>>>> 未知类型: "..tag )
	end
end

-- 更新装备强化UI显示状态
function ClassRef:setEquipGridStrengthPanelVisble( flag )
	self._equipGridStrengthPanelShown = flag

	if flag then
		for i,equip in ipairs( self._equips ) do
			equip:setEquipGridStrengthPanelVisble( flag )
			if string.find( GD:getSystemStrPar("recastlocation", "nil"), tostring( i ) ) then
				equip:setColor( display.COLOR_WHITE )
			else
				equip:setColor( display.COLOR_GRAY )
			end
		end
	else
		for i,equip in ipairs( self._equips ) do
			equip:setEquipGridStrengthPanelVisble( flag )
			equip:setColor( display.COLOR_WHITE )
		end
	end
end

-- 刷新dragonbones动画
function ClassRef:refreshPlayer(params, fashionId, isOff)
	params.mountID = 0 -- 不显示坐骑
	self._isMount = (params.mountID and params.mountID~=0)

	local hero = self._ui.Node_position:getChildByTag(0)
	if hero and fashionId ~= nil then
		-- 局部替换装备
		AvatarFactory.changeEquip(hero, params, fashionId, isOff)
	else
		self:performWithDelay(function()
			params.inBattle = false
			local hero = AvatarFactory.createHero(params)
			hero:setTag(0)
			self._hero = hero
			self._ui.Node_position:removeAllChildren()
			self._ui.Node_position:addChild(hero)
			self._playIndex = nil
			self:playNextAnimation()
		end, 0.2)
	end
end

local PlayerAnimations = {"mapidle","mapwalk","style1","mapmove","angry","celebrate","confusion","happy","seriously"}
local MountAnimations = {"ride_idle","ride_move"}

function ClassRef:playNextAnimation()
	local hero = self._hero
	if hero then
		local animations = self._isMount and MountAnimations or PlayerAnimations
		if not self._playIndex or self._playIndex >= #animations then
			self._playIndex = 0
		end
		self._playIndex = self._playIndex + 1
		hero:playAni({name=animations[self._playIndex],next=animations[1]})
	end
end

-- 预览时装
-- data = { [location] = fashionID } -- 5个可幻化位的预览信息
function ClassRef:previewClothes( data )
	local heroParams = UD:getAvatarParams()
	--因为要求没装备也可以预览 所以改为如下
	-- for k, fashionId in pairs( heroParams.fashionIDs ) do
	-- 	local fashionCfg = GD:getClothesConfig( fashionId )
	-- 	if not fashionCfg then
	-- 		fashionCfg = GD:getEquipConf( fashionId )
	-- 	end
	-- 	local clothesId = data[tonumber( fashionCfg.location )]
	-- 	if clothesId then
	-- 		heroParams.fashionIDs[k] = clothesId
	-- 		data[tonumber( fashionCfg.location )] = nil
	-- 	end
	-- end

	-- for k,v in pairs(data) do
	-- 	table.insert(heroParams.fashionIDs,v)
	-- end

	-- 预览头部时，不遵循玩具优先的规则。
	for k, v in pairs(data) do
		heroParams.fashionIDs = GD:attachPreviewFashionId(heroParams.fashionIDs, v)
	end

	self:refreshPlayer(heroParams)
end

function ClassRef:setCorePropBtnVisible( trueOrFalse )
	-- body
	if UIHandler:isFunctionOpen(Constant.FUNC_TYPE_CORE_PROP) and self._isOtherPlayer ~= true then
		self._ui["Panel/Panel_top/Button_CoreProp"]:setVisible( trueOrFalse )
	else
		self._ui["Panel/Panel_top/Button_CoreProp"]:setVisible( false )
	end
end

function ClassRef:setRecastMasterBtnVisible( trueOrFalse)
	if self._isOtherPlayer ~= true then
		self._ui["Panel/Panel_top/Button_qh"]:setVisible(trueOrFalse)
	else
		self._ui["Panel/Panel_top/Button_qh"]:setVisible(false)
	end
end

function ClassRef:setIsOtherPlayer(trueOrFalse)
	self._isOtherPlayer = trueOrFalse
	self:setCorePropBtnVisible(true)
	self._ui["Panel/btn_show"]:setVisible(self._isOtherPlayer ~= true)
	self:setRecastMasterBtnVisible(self._isOtherPlayer)
end

function ClassRef:registerOnOperate( cb )
	self._onPanelHandler = cb
end

function ClassRef:refreshRedPonit()
	self._ui["Panel/Panel_top/Button_CoreProp/dotNew"]:setVisible(UD.redPoint:getStateByKey(Constant.FUNC_TYPE_CORE_PROP))
	self._ui["Panel/Panel_top/Button_qh/dot"]:setVisible(UD.redPoint:getStateByKey(RedPointConstant.RecastMonster_Exchange))
end

function ClassRef:refreshHiddenBtnState()
    local equipGrid = UD:getEquipGridByPos(Enums.EquipType.head) --获得头部位置装备信息
    local isHidden = equipGrid:getHidden() --获得头部位置显隐状态
    self._ui["Panel/btn_show"]:setBright(not isHidden)     
end

-- 刷新强化大师
function ClassRef:updateRecastMaster(curMasterList, nextMasterList)
	curMasterList = curMasterList
	nextMasterList = nextMasterList
	local masterNode = self._ui["Panel/Panel_animation/top"]:getChildByName( "Panel" ):getChildByName( "Panel_qh" )
	local curMasterNode = masterNode:getChildByName("data_1")
	local nextMasterNode = masterNode:getChildByName("data_2")
	--刷新强化大师红点
	UD.redPoint:setStateByKey(RedPointConstant.RecastMonster_Exchange, false)
	-- 初始化控件全部隐藏
	local function initNode(node)
		node:findChild("Panel/Image_2"):setVisible(false)
		node:findChild("Panel/tlt"):setVisible(false)
		node:findChild("Panel/zero"):setVisible(false)
		node:findChild("Panel/max"):setVisible(false)
		for i = 1, 3 do
			node:findChild("Panel/data_tlt_"..i):setVisible(false)
			node:findChild("Panel/data_num_"..i):setVisible(false)
			node:findChild("Panel/symbol_"..i):setVisible(false)
		end
	end
	local function initRecastMasterNode(node, list, type)
		local node = node
		local list = list
		if not node then return end
		initNode(node)		
		if list then
			local targetLv = list.targetLv
			local info = list.propInfo
			node:findChild("Panel/Image_2"):setVisible(true)
			node:findChild("Panel/tlt"):setVisible(true)
			local str = (type == 1) and L("RecastMasterCurrent") or L("RecastMasterNext")
			node:findChild("Panel/tlt"):setString(string.format(str, targetLv))
			if type == 2 then
				-- 下一级半透明
				display.setCascadeOpacityEnabled(node, true)
			end
			for i = 1, 3 do
				local singleInfo = info[i]
				local nameNode = node:findChild("Panel/data_tlt_"..i)
				local numNode = node:findChild("Panel/data_num_"..i)
				if singleInfo then
					local name = string.gsub(L(singleInfo.name), "：+","") or ""
					name = string.gsub(name, ":+","") or ""
					nameNode:setString(name)
					local str = (singleInfo.format == 2) and tostring( singleInfo.num/100 ).."%" or singleInfo.num
					numNode:setString("+"..str)
					nameNode:setVisible(true)
					numNode:setVisible(true)
					node:findChild("Panel/symbol_"..i):setVisible(true)
				end
			end
		else
			if type == 1 then --当前
				node:findChild("Panel/zero"):setVisible(true)
				node:findChild("Panel/zero"):setString(L("RecastMasterNotActivation"))
			else --下一级
				masterNode:getChildByName("bg1"):setVisible(false)
				masterNode:getChildByName("bg2"):setVisible(false)
				masterNode:getChildByName("bg3"):setVisible(true)
				masterNode:getChildByName("jt"):setVisible(false)
				masterNode:getChildByName("max"):setVisible(true)
				masterNode:findChild("max/tlt"):setString(L("RecastMasterMax"))
				display.setCascadeOpacityEnabled(node, false)
			end
		end
	end
	initRecastMasterNode(curMasterNode, curMasterList, 1)
	initRecastMasterNode(nextMasterNode, nextMasterList, 2)
end

----一键强化------
----首先要获取全身可以强化的部位，根据材料算出来可以强化的部位装备以及等级---------------


return ClassRef
